package com.xdqzy.baseline.common.config;

import com.xdqzy.baseline.common.service.impl.LocalFileServerService;
import com.xdqzy.baseline.common.service.impl.OssServerService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author : winter
 * @version V1.0
 * @Title: 文件服务器配置
 * @ClassName : com.ctbc.backend.common.config.FileServerConfig.java
 * @Description :
 * @date :  2020-11-03 23:01
 */
@EnableConfigurationProperties(FileServerProperties.class)
@Configuration
public class FileServerConfig {

    @Resource
    private FileServerProperties fileServerProperties;

    @Bean
    @ConditionalOnProperty(value = "file.server.upload-type", havingValue = "local")
    public LocalFileServerService localFileServerService() {
        return new LocalFileServerService(fileServerProperties.getLocalServer());
    }

    @Bean
    @ConditionalOnProperty(value = "file.server.upload-type", havingValue = "oss")
    public OssServerService ossServerService() {
        return new OssServerService(fileServerProperties.getOssServer());
    }


}
